
<!--top结束-->
<script type="text/javascript" src="<?= base_url() ?>resource/js/layer/layer.js"></script>
<div class="mian">
    <div class="mian1">
        <div class="mian2">
            <!--left start-->
            <?php $this->load->view('defaults/common/left'); ?>
            <!--left end-->
            <!--right start-->
            <div class="right">
                <!--breadcrumb start-->
                <div class="righta"><?= $this->breadcrumb->generateHTML(); ?> </div>
                <!--breadcrumb end-->
                <!-- contents start -->
                <div id="contents">
                    <div id="contents_container">
                        <form id='in_stock_form' action="<?= blang_url('wms/InStock/n_stock') ?>" method="post" name="myform" onsubmit="return myform_submit()" autocomplete="off" >
                            <table cellpadding="0" cellspacing="0" id="table_forms" border="1">
                                <tr>
                                    <td class="forms_left"><?=lang('wms_ckdm')?>:</td>
                                    <td>
                                        <select  name="whs_code"  placeholder="whs_code">
                                           <?php foreach($whsCode as $oneWhs){?>
                                                  <option value ="<?=$oneWhs['whs_code']?>"><?='('.$oneWhs['whs_code'].')'.$oneWhs['whs_name']?></option>  
                                                                        <?php }?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="forms_left"><?= lang('wms_panel_30004') ?>:</td>
                                    <td>
                                        <select  id="in_out_type" name="in_out_type"  placeholder="in_out_type">
                                            <?php foreach ($in_out_type as $type)
                                            { ?>
                                                <option value ="<?= $type['key'] ?>"><?= $type['name_cn'] ?></option>  
<?php } ?>
                                        </select></td>
                                </tr>
                                <tr>
                                    <td class="forms_left">SKU:</td>
                                    <td><input id="sku" type="text" name="sku" value="" onchange="check_sku(this.value)" /></td>
                                </tr>
                                <tr>
                                    <td class="forms_left"><?=lang('product_wlsl')?>:</td>
                                    <td><input id="quantity" name="quantity" value="" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" /></td>
                                </tr>
                                <tr>
                                    <td class="forms_left"><?= lang('wms_panel_30005') ?>:</td>
                                    <td><textarea rows="2" cols="50" id="comments" name="comments" value=""></textarea></td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2" class="sub_padding_right">
                                        <button type="button" onclick="stockin()"  style="margin-right: 20px;width: 150px; height: 30px; margin-left: 200px;" ><?=lang('wms_qrrk')?></button>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="forms_left"  colspan="2"  id="msg"></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </div>
                <!-- contents end -->
            </div>
            <!--right end-->
            <div class="clear"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(window).load(function() {
        $("#sku").focus();
    }); 
    $('#sku').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            $("#quantity").focus();
        }
    });
    $('#quantity').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            stockin()
        }
    });
    function stockin(){
        //loading层
        var LDindex;
        $.ajax({
            type:'post',
            timeout:60000,
            data: $("#in_stock_form").serializeArray(),
            url:"<?= blang_url('wms/InStock/n_stock') ?>",
            beforeSend:function(XMLHttpRequest){
                LDindex = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                })
            }, 
            success: function (rs) {
                layer.close(LDindex); 
                obj=JSON.parse(rs);
                if(true==obj.success){
                    $('#sku').val("");
                    $('#quantity').val("");
                    $('#comments').val("");
                    $("#sku").focus();
                    $("#msg").html('Success!'+obj.msg);
                }
                else{
                    alert(obj.msg);
                    $("#sku").focus();
                }
            },
            error: function (e, jqxhr, settings, exception) {

            },
            complete : function(XMLHttpRequest,status){
                layer.close(LDindex); 
                if(status=='timeout'){
                    alert("Request timed out,Please try again!");
                }
            }
        });
    }
    function check_sku(sku){
     var LDindex;
        $.ajax({
            type:'post',
            timeout:60000,
            url:"<?= blang_url('wms/InStock/check_sku') ?>"+'/'+sku,
            beforeSend:function(XMLHttpRequest){
                LDindex = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                })
            }, 
            success: function (rs) {
                layer.close(LDindex); 
                obj=JSON.parse(rs);
                if(true==obj.success){
                    $("#quantity").focus();
                }
                else{
                    alert(obj.msg+':'+sku);
                    $('#sku').val("");
                    $("#sku").focus();
                }
            },
            error: function (e, jqxhr, settings, exception) {

            },
            complete : function(XMLHttpRequest,status){
                layer.close(LDindex); 
                if(status=='timeout'){
                    alert("Request timed out,Please try again!");
                }
            }
        });
    }
</script>
